function changeTitleName(name) {
	$(document).find('#toggle-btn .mobile-text').text(name)
}

function loctionNav() {
	// 从本地存储获取导航栏状态
	const navState = localStorage.getItem('navState');
	const sidebar = $(document).find('#sidebar');
	const content = $(document).find('#content');
	const logo = $(document).find('.logo');
	const toggleText = $(document).find('#toggle-btn .desktop-text');


	// 初始化导航栏状态
	if (navState === 'hidden') {
		sidebar.addClass('hidden');
		content.addClass('expanded');
		logo.addClass('hidden');
		toggleText.addClass('layui-icon-shrink-right');
	}

}

(function () {
	// $("[data-load]").each(function () {
	// 	$(this).load($(this).attr("data-load") + ".html", function () {
	// 		$($(this)[0].innerHTML).insertBefore($(this))
	// 		$(this).remove()
	// 		loctionNav()
	// 	});
	// });

	loctionNav()

	// 切换导航栏和logo显示状态
	$(document).on('click', '#toggle-btn', function () {

		const sidebar = $(document).find('#sidebar');
		const content = $(document).find('#content');
		const logo = $(document).find('.logo');
		const toggleText = $(document).find('#toggle-btn .desktop-text');

		sidebar.toggleClass('hidden');
		content.toggleClass('expanded');
		logo.toggleClass('hidden');
		toggleText.removeClass('layui-icon-spread-left').removeClass('layui-icon-shrink-right')
		// 更新按钮文本
		if (sidebar.hasClass('hidden')) {
			toggleText.addClass('layui-icon-shrink-right');
			localStorage.setItem('navState', 'hidden');
		} else {
			toggleText.addClass('layui-icon-spread-left');
			localStorage.setItem('navState', 'visible');
		}
	});

	// 左侧菜单点击效果
	$(document).on('click', '.menu-item .title', function () {

		$this = $(this).closest('.menu-item')
		$('.menu-item').removeClass('active');
		$this.addClass('active');
		$this.find('dl').slideToggle('slow')
	});

	// 响应窗口大小变化
	$(window).resize(function () {
		const navState = localStorage.getItem('navState');
		const sidebar = $(document).find('#sidebar');
		const content = $(document).find('#content');
		const logo = $(document).find('.logo');
		if ($(window).width() < 768) {
			sidebar.addClass('hidden');
			content.addClass('expanded');
			logo.addClass('hidden');
		} else if (navState !== 'hidden') {
			sidebar.removeClass('hidden');
			content.removeClass('expanded');
			logo.removeClass('hidden');
		}
	});
	layui.use('util', function () {
		var util = layui.util;
		var upload = layui.upload;
		var $ = layui.$;

		util.on({
			//点击跳转url
			url: function () {
				if ($(this).attr('href')) {
					window.location = $(this).attr('href')
				}
			},

			picture: function () {
				var url = $(this).attr('href')
				layer.photos({
					photos: {
						"title": "Photos Demo",
						"start": 0,
						"data": [
							{
								"alt": "layer",
								"pid": 1,
								"src": url,
							}
						]
					}
				})
			}
		})
		// 上传按钮
		upload.render({
			elem: '.uploadImg',
			url: '', // 实际使用时改成您自己的上传接口即可。
			before: function (obj) {

				$this = $(this.elem);
				// 预读本地文件示例，不支持ie8
				obj.preview(function (index, file, result) {
					$this.find('[data-img]').attr('src', result); // 图片链接（base64）
					console.log(result)
				});

			},
			done: function (res) {

			},

		});
	})
	// 回到顶部功能
	$(document).on("click", "[back-btn]", function (event) {
		event.preventDefault();
		$("html, body").animate(
			{
				scrollTop: 0,
			},
			600
		);
		return false;
	});


})()
